/*
 * print.c
 *
 *  Created on: Sep 13, 2012
 *      Author: jacco
 */

#include "print.h"

/* convert logic value to character*/
char logic_to_char(int val)
{
	char out='U';

	if (val == LOGIC_0)
	{
		out = '0';
	}
	else if (val == LOGIC_1)
	{
		out = '1';
	}
	else if (val == LOGIC_X)
	{
		out = 'X';
	}
	else
	{
		out = 'U'; //Unknown / Undefined
	}
	return out;
}

/*Convert a integer array to a string and print the string */
void print_vector (int vect[], int size)
{
	char txt_vect[size];
	int i = 0;

	for(i=0;i<size;i++)
	{
		txt_vect[i] = logic_to_char(vect[size-1-i]);
	}
	txt_vect[i] = '\0';

	printf("%s",txt_vect);

}

/*convert character to logic value*/
int char_to_logic (char val)
{
	int out=LOGIC_X;

	if (val == '0')
	{
		out = LOGIC_0;
	}
	else if (val == '1')
	{
		out = LOGIC_1;
	}
	else if (val == 'X')
	{
		out = LOGIC_X;
	}
	else
	{
		out = -1; //invalid input
	}

	return out;
}
